﻿using System;
using System.Collections;
using System.Data;
using CE.Database;

/// <summary>
/// Summary description for CarPremiumClaimLoadingDB
/// </summary>
/// 
namespace CE.Provider
{
    public class CarPremiumClaimLoadingDB
    {
        public CarPremiumClaimLoadingDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(CarPremiumClaimLoading CarPremiumClaimLoading)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocProviderCarPremiumClaimLoadingInsertUpdateSingleItem]";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@ProviderPreCLId", CarPremiumClaimLoading.ProviderPreCLId);
            _sPara.Add("@ProviderCompanyId", CarPremiumClaimLoading.ProviderCompanyId);
            _sPara.Add("@NoOfClaim", CarPremiumClaimLoading.NoOfClaim);
            _sPara.Add("@ClaimAmt", CarPremiumClaimLoading.ClaimAmt);
            _sPara.Add("@NCD", CarPremiumClaimLoading.NCD);
            _sPara.Add("@AdoptedLoading", CarPremiumClaimLoading.AdoptedLoading);
            _sPara.Add("@Rate", CarPremiumClaimLoading.Rate);
            _sPara.Add("@RefCEUserId", CarPremiumClaimLoading.RefCEUserId);
            _sPara.Add("@Status", CarPremiumClaimLoading.Status);
            _sPara.Add("@Info1", CarPremiumClaimLoading.Info1);
            _sPara.Add("@Dinfo1", CarPremiumClaimLoading.DInfo1);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public CarPremiumClaimLoadingList GetProviderCarPremiumClaimLoadingList(Int64 ProviderCompanyId)
        {
            CarPremiumClaimLoadingList _CarPremiumClaimLoadinglist = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarPremiumClaimLoadingSelectItemList";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _CarPremiumClaimLoadinglist = new CarPremiumClaimLoadingList();
                    for (int i = 0; i < _dt.Rows.Count; i++)
                    {
                        CarPremiumClaimLoading _CarPremiumClaimLoading = new CarPremiumClaimLoading();
                        _CarPremiumClaimLoading = FillDataRecord(_dt, i);
                        _CarPremiumClaimLoadinglist.Add(_CarPremiumClaimLoading);
                    }
                }
            }
            return _CarPremiumClaimLoadinglist;
        }


        public CarPremiumClaimLoading GetProviderCarPremiumClaimLoading(Int64 ProviderCompanyId, Int32 ProviderPreCLId)
        {
            CarPremiumClaimLoading _vehicleyear = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarPremiumClaimLoadingSelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);
            _spara.Add("@ProviderPreCLId", ProviderPreCLId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _vehicleyear = new CarPremiumClaimLoading();
                    _vehicleyear = FillDataRecord(_dt, 0);
                }
            }
            return _vehicleyear;
        }

        public CarPremiumClaimLoading GetProviderCarPremiumClaimLoading(Int64 ProviderNCDFactorId)
        {
            CarPremiumClaimLoading _vehicleyear = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarPremiumClaimLoadingSelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderPreCLId", ProviderNCDFactorId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _vehicleyear = new CarPremiumClaimLoading();
                    _vehicleyear = FillDataRecord(_dt, 0);
                }
            }
            return _vehicleyear;
        }

        private CarPremiumClaimLoading FillDataRecord(DataTable myDataTable, int RowId)
        {
            CarPremiumClaimLoading myCarPremiumClaimLoading = new CarPremiumClaimLoading();
            myCarPremiumClaimLoading.ProviderPreCLId = Convert.ToInt64(myDataTable.Rows[RowId]["ProviderPreCLId"].ToString());
            myCarPremiumClaimLoading.ProviderCompanyId = Convert.ToInt64(myDataTable.Rows[RowId]["ProviderCompanyId"].ToString());
            myCarPremiumClaimLoading.NoOfClaim = Convert.ToInt32(myDataTable.Rows[RowId]["NoOfClaim"].ToString());
            myCarPremiumClaimLoading.ClaimAmt = myDataTable.Rows[RowId]["ClaimAmt"].ToString();          
            myCarPremiumClaimLoading.NCD = myDataTable.Rows[RowId]["NCD"].ToString();
            myCarPremiumClaimLoading.AdoptedLoading = myDataTable.Rows[RowId]["AdoptedLoading"].ToString();
            myCarPremiumClaimLoading.Rate = Convert.ToSingle(myDataTable.Rows[RowId]["Rate"].ToString());
            myCarPremiumClaimLoading.RefCEUserId = Convert.ToInt64(myDataTable.Rows[RowId]["RefCEUserId"].ToString());
            myCarPremiumClaimLoading.Status = Convert.ToBoolean(myDataTable.Rows[RowId]["Status"].ToString());
            myCarPremiumClaimLoading.ModifiedDate = Convert.ToDateTime(myDataTable.Rows[RowId]["ModifiedDate"].ToString());

            if (myDataTable.Rows[RowId]["Info1"].ToString() != "")
                myCarPremiumClaimLoading.Info1 = myDataTable.Rows[RowId]["Info1"].ToString();

            if (myDataTable.Rows[RowId]["DInfo1"].ToString() != "")
                myCarPremiumClaimLoading.DInfo1 = Convert.ToDateTime(myDataTable.Rows[RowId]["DInfo1"].ToString());
            else
                myCarPremiumClaimLoading.DInfo1 = Convert.ToDateTime(myDataTable.Rows[RowId]["ModifiedDate"].ToString());

            return myCarPremiumClaimLoading;
        }
    }
}
